package lesson14.thrift;

import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.*;

/**
 * <br/>
 * Created on : 2018-06-12 23:57
 * @author lizebin
 */
public class Server {

    public static void main(String[] args) {
        try {
            TNonblockingServerSocket socket = new TNonblockingServerSocket(8899);
            THsHaServer.Args arg = new THsHaServer.Args(socket).minWorkerThreads(2).maxWorkerThreads(4);
            PersonService.Processor<PersonServiceImpl> processor = new PersonService.Processor<>(new PersonServiceImpl());

            arg.protocolFactory(new TCompactProtocol.Factory());//协议层:压缩协议
            arg.transportFactory(new TFramedTransport.Factory());//传输层
            arg.processorFactory(new TProcessorFactory(processor));

            TServer server = new THsHaServer(arg);//半同步半异步

            server.serve();
        } catch (TTransportException e) {
            e.printStackTrace();
        } finally {

        }

    }

}
